<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="产品id" prop="productId">
        <el-input v-model="queryParams.productId" placeholder="请输入产品id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="备注信息" prop="remarkInfo">
        <el-input v-model="queryParams.remarkInfo" placeholder="请输入备注信息" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="账户余额" prop="totalAmount">
        <el-input v-model="queryParams.totalAmount" placeholder="请输入账户余额" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属用户ID" prop="ownerId">
        <el-input v-model="queryParams.ownerId" placeholder="请输入所属用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="small" @click="handleAdd"
          v-hasPermi="['account:productInfo:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="small" :disabled="single" @click="handleUpdate"
          v-hasPermi="['account:productInfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="small" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['account:productInfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="small" @click="handleExport"
          v-hasPermi="['account:productInfo:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productInfoList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="账户ID" align="center" prop="id" /> -->
      <!-- <el-table-column label="产品id" align="center" prop="productId" /> -->
      <el-table-column label="产品账户" align="center" prop="productName" >
        <template slot-scope="scope">
          {{ scope.row.productName }}[{{ scope.row.productId }}]
        </template>
      </el-table-column>
      <el-table-column label="账户余额" align="center" prop="totalAmount" />
      <el-table-column label="备注信息" align="center" prop="remarkInfo" />
      <el-table-column label="商务信息" align="center" prop="ownerId" >
        <template slot-scope="scope">
            {{ scope.row.ownerName }}[{{ scope.row.ownerId }}]
          </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['account:productInfo:edit']">修改</el-button>
          <!-- <el-button size="small" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['account:productInfo:remove']">删除</el-button> -->
          <el-button size="small" type="text" icon="el-icon-delete" @click="handledetail(scope.row.productId)"
            v-hasPermi="['account:productInfoHis:list']">流水详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改产品账户信息对话框 -->
    <el-drawer size="30%" :title="title" :visible.sync="open">
      <div class="demo-drawer-form">
        <div class="demo-drawer-form__content">
          <div class="flex">
      <el-form ref="form" :model="form" :rules="rules" label-width="88px">
        <!-- <el-form-item label="产品id" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品id" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item> -->
        <el-form-item label="备注信息" prop="remarkInfo">
          <el-input v-model="form.remarkInfo" placeholder="请输入备注信息" />
        </el-form-item>
        <!-- <el-form-item label="账户余额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入账户余额" />
        </el-form-item>
        <el-form-item label="所属用户ID" prop="ownerId">
          <el-input v-model="form.ownerId" placeholder="请输入所属用户ID" />
        </el-form-item> -->
      </el-form>
      </div>
        </div>
        <div slot="footer" class="dialog-footer demo-drawer-form__footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      </div>
    </el-drawer>

    
  </div>
</template>

<script>
import { listProductInfo, getProductInfo, delProductInfo, addProductInfo, updateProductInfo, detProductInfo } from "@/api/account/productInfo";

export default {
  name: "ProductInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //详情数组
      tableData: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品账户信息表格数据
      productInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: null,
        productName: null,
        remarkInfo: null,
        totalAmount: null,
        ownerId: null,
      },
      dialogVisible: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
       
      },
    };
  },
  created() {
    this.getList();
  },
  methods: { 
    //详情
    handledetail(id) {
      this.$router.push({path: '/productInfoHis', query: {id: id}})
    },

    /** 查询产品账户信息列表 */
    getList() {
      this.loading = true;
      listProductInfo(this.queryParams).then(response => {
        this.productInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productId: null,
        productName: null,
        remarkInfo: null,
        totalAmount: null,
        ownerId: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产品账户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProductInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产品账户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProductInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProductInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除产品账户信息编号为"' + ids + '"的数据项？').then(function () {
        return delProductInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('account/productInfo/export', {
        ...this.queryParams
      }, `productInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
